package com.sicheng.lc.周赛.分类.栈;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/25 15:59
 */
public class 美化数组的最少删除数 {
    //https://leetcode.cn/problems/minimum-deletions-to-make-array-beautiful/
    public int minDeletion(int[] nums) {
        //套路：从前往后遍历 + 需要考虑相邻元素 + 有消除操作 = 栈
        int size = 0;
        int top = Integer.MIN_VALUE;
        for (int num : nums) {
            if ((size & 1) == 0) {
                top = num;
                size++;
            } else if (num != top) {
                size++;
                top = num;
            }
        }
        return nums.length - size;
    }
}
